﻿#include "PyFITKPhyscisPropBeam.h"
#include "FITKAcousticsPhysics.h"
#include "FITKAcousticsAbsPhysicsProp.h"
#include "FITKPhyscisPropertyBeam.h"
#include "FITKAcousticsAbsMaterial.h"
namespace Acoustics
{
    PyFITKPhyscisPropBeam::PyFITKPhyscisPropBeam(const QString & name) :
        Acoustics::PyFITKPhyscisPropBase(name)
    {
    }

    bool PyFITKPhyscisPropBeam::setMoments(double Ixx, double Iyy, double Jzz, double Qzz)
    {
        if (!_phyProp)return false;
        if (Ixx < 0 || Iyy < 0 || Jzz < 0 || Qzz < 0)return false;

        FITKPhyscisPropertyBeam *beam = dynamic_cast<Acoustics::FITKPhyscisPropertyBeam*>(_phyProp);
        if (!beam)return false;

        beam->setSecondMomentX(Ixx);
        beam->setSecondMomentY(Iyy);
        beam->setPolarMoment(Jzz);
        beam->setTorsionalConstant(Qzz);
        return true;
    }

    bool PyFITKPhyscisPropBeam::setCrossSection(double area, double perimeter)
    {
        if (!_phyProp)return false;
        if (area < 0 || perimeter < 0)return false;

        FITKPhyscisPropertyBeam *beam = dynamic_cast<Acoustics::FITKPhyscisPropertyBeam*>(_phyProp);
        if (!beam)return false;

        beam->setCrossSectionArea(area);
        beam->setPerimeter(perimeter);
        return true;
    }

    bool PyFITKPhyscisPropBeam::setShearCenterOffset(double ShearOffsetX, double ShearOffsetY)
    {
        if (!_phyProp)return false;

        FITKPhyscisPropertyBeam *beam = dynamic_cast<Acoustics::FITKPhyscisPropertyBeam*>(_phyProp);
        if (!beam)return false;

        beam->setShearOffsetX(ShearOffsetX);
        beam->setShearOffsetY(ShearOffsetY);
        return true;
    }

    bool PyFITKPhyscisPropBeam::setMaterial(const QString & material)
    {
        if (!_phyProp)return false;

        Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
        if (phy == nullptr) return false;
        Acoustics::FITKAcousticsMaterialManager* matMgr = phy->getMaterialManager();
        if (matMgr == nullptr) return false;
        if (!matMgr->getDataByName(material))return false;
        //类型判断？

        int id = matMgr->getDataByName(material)->getDataObjectID();
        FITKPhyscisPropertyBeam *beam = dynamic_cast<Acoustics::FITKPhyscisPropertyBeam*>(_phyProp);
        if (!beam)return false;

        beam->setMaterialID(id);
        return true;
    }

    bool PyFITKPhyscisPropBeam::createPhyscisProp(const QString & name)
    {
        if (name == "")return false;
        Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
        if (phy == nullptr) return false;
        Acoustics::FITKAcousticsPhysicsPropManager* propMgr = phy->getPhysicsPropManager();
        if (propMgr == nullptr) return false;
        if (propMgr->getDataByName(name))return false;

        FITKPhyscisPropertyBeam * beam = new FITKPhyscisPropertyBeam();
        beam->setDataObjectName(name);
        _phyProp = beam;
        propMgr->appendDataObj(_phyProp);
        return true;
    }
}